package com.cooper.controllers.item;

import org.springframework.beans.factory.annotation.Autowired;

import com.cooper.constants.AppConstants;
import com.cooper.controllers.Controller;
import com.cooper.pagination.PageInfo;
import com.cooper.pagination.PageResult;
import com.cooper.service.item.ItemRepository;
import com.cooper.vo.ItemInfoVo;
import com.cooper.vo.ItemSearchVo;

import net.paoding.rose.web.Invocation;
import net.paoding.rose.web.annotation.rest.Get;
import net.paoding.rose.web.annotation.rest.Post;

public class ListController extends Controller {

	@Autowired
	private ItemRepository itemRepository;
	
	@Get @Post
	public String execute(Invocation inv, ItemSearchVo searchVo, PageInfo pageInfo) throws Exception{
		pageInfo.setPageSize(ITEMS_PER_PAGE);
		PageResult<ItemInfoVo> pageResult = this.itemRepository.doSearch(searchVo, pageInfo);
		inv.addModel("entryList", pageResult.getResult());
		inv.addModel(AppConstants.pageInfo, pageInfo);
		inv.addModel("searchVo", searchVo);
		inv.addModel("keyword", searchVo.getKeyword());
		return "ItemList";
	}
	
}
